package com.mmall.user.provider.service;

import com.mmall.user.api.bo.UserAddressBO;
import com.mmall.user.api.service.UserAddressService;
import com.mmall.user.provider.convert.UserAddressConvert;
import com.mmall.user.provider.dao.UserAddressMapper;
import com.mmall.user.provider.model.UserAddressDO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.validation.constraints.NotNull;

/**
 * @author hejianglong
 * @date 2019/10/25
 */
@Service(version = "1.0.0")
@Component
public class UserAddressServiceImpl implements UserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Override
    public UserAddressBO getDefaultUserAddress(@NotNull Long userId) {
        UserAddressDO userAddressDO = userAddressMapper.selectDefaultAddressByUserId(userId);
        return UserAddressConvert.INSTANCE.convert(userAddressDO);
    }

    @Override
    public UserAddressBO getUserAddress(@NotNull Long userAddressId) {
        UserAddressDO userAddressDO = userAddressMapper.selectById(userAddressId);
        return UserAddressConvert.INSTANCE.convert(userAddressDO);
    }
}
